package com.ruoyi.web.controller;

import com.ruoyi.web.core.config.KafkaConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class KafkaProviderController {

//    @Autowired
//    private KafkaTemplate<Object, Object> template;

    /**
     * 发送事务消息
     *
     * @param msg
     */
    @PostMapping(path = "/sendTransaction")
    public String sendTransaction(@RequestBody String msg) {
//        this.template.send(KafkaConfig.TOPIC_TRANSACTION, msg);
//        this.template.executeInTransaction(kafkaTemplate -> {
//            StringUtils.commaDelimitedListToSet(msg).stream()
//                    .map(s -> s)
//                    .forEach(data -> {
//                                kafkaTemplate.send(KafkaConfig.TOPIC_TRANSACTION, data);
//                                if(data.contains("exception")){
//                                    throw new RuntimeException("occur exception!");
//                                }
//                            }
//                    );
//            return null;
//        });

        return " send batch msg: " + msg;
    }

}
